package com.zhangxin.aiInterview.manager.redis.audio_emotion;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;

/**
 * 音频情感数据存储服务
 */
@Component
public class SetAudioEmotion {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 存储单条音频情感数据
     * @param userId 用户ID
     * @param emotion 情感数据
     */
    public void storeEmotion(Long userId, String emotion) {
        try {
            String key = getKey(userId);
            stringRedisTemplate.opsForList().rightPush(key, emotion);
        } catch (Exception e) {
            System.out.println("Redis存储音频情感数据失败: " + e.getMessage());
        }
    }

    /**
     * 批量存储音频情感数据
     * @param userId 用户ID
     * @param emotions 情感数据列表
     */
    public void storeEmotions(Long userId, List<String> emotions) {
        try {
            String key = getKey(userId);
            stringRedisTemplate.opsForList().rightPushAll(key, emotions);
        } catch (Exception e) {
            System.out.println("Redis批量存储音频情感数据失败: " + e.getMessage());
        }
    }

    private String getKey(Long userId) {
        return "AI_interview:audioEmotion:" + userId;
    }
}